﻿#include <vector>
#include <list>
#include <gtest/gtest.h>
#include "strutil.h"

using acutil::string::Upper;
using acutil::string::Lower;
using acutil::string::ToUpper;
using acutil::string::ToLower;

namespace {
  class UpperLowerTest : public testing::Test {
  public:
    UpperLowerTest()
      :s1_("fOo1B2Ar"), s1_upper_("FOO1B2AR"), s1_lower_("foo1b2ar"),
       s2_(L"F1oObA5r"), s2_upper_(L"F1OOBA5R"), s2_lower_(L"f1ooba5r"),
       empty_(""), empty2_(L"")
    {};
  protected:
    const std::string s1_, s1_upper_, s1_lower_;
    const std::wstring s2_, s2_upper_, s2_lower_;
    const std::string empty_;
    const std::wstring empty2_;
  };
} // namespace

TEST_F(UpperLowerTest, ConstString){
  EXPECT_STREQ(s1_upper_.c_str(), Upper(s1_).c_str());
  EXPECT_STREQ(s1_upper_.c_str(), Upper(s1_lower_).c_str());
  EXPECT_STREQ(s2_upper_.c_str(), Upper(s2_).c_str());
  EXPECT_STREQ(s2_upper_.c_str(), Upper(s2_lower_).c_str());
  EXPECT_STREQ(s1_lower_.c_str(), Lower(s1_).c_str());
  EXPECT_STREQ(s1_lower_.c_str(), Lower(s1_upper_).c_str());
  EXPECT_STREQ(s2_lower_.c_str(), Lower(s2_).c_str());
  EXPECT_STREQ(s2_lower_.c_str(), Lower(s2_upper_).c_str());
}

TEST_F(UpperLowerTest, NeverChange){
  EXPECT_STREQ(s1_upper_.c_str(), Upper(s1_upper_).c_str());
  EXPECT_STREQ(s2_upper_.c_str(), Upper(s2_upper_).c_str());
  EXPECT_STREQ(s1_lower_.c_str(), Lower(s1_lower_).c_str());
  EXPECT_STREQ(s2_lower_.c_str(), Lower(s2_lower_).c_str());
}

TEST_F(UpperLowerTest, EmptyString){
  EXPECT_STREQ(empty_.c_str(), Upper(empty_).c_str());
  EXPECT_STREQ(empty2_.c_str(), Upper(empty2_).c_str());
}

TEST_F(UpperLowerTest, Rvalue){
  EXPECT_STREQ(s1_upper_.c_str(), Upper(std::string(s1_)).c_str());
  EXPECT_STREQ(s1_upper_.c_str(), Upper(std::string(s1_lower_)).c_str());
  EXPECT_STREQ(s2_upper_.c_str(), Upper(std::wstring(s2_)).c_str());
  EXPECT_STREQ(s2_upper_.c_str(), Upper(std::wstring(s2_lower_)).c_str());
  EXPECT_STREQ(s1_lower_.c_str(), Lower(std::string(s1_)).c_str());
  EXPECT_STREQ(s1_lower_.c_str(), Lower(std::string(s1_upper_)).c_str());
  EXPECT_STREQ(s2_lower_.c_str(), Lower(std::wstring(s2_)).c_str());
  EXPECT_STREQ(s2_lower_.c_str(), Lower(std::wstring(s2_upper_)).c_str());
}

TEST_F(UpperLowerTest, TransformInPlace){
  std::string s1(s1_);
  std::wstring s2(s2_);
  ToUpper(s1);
  EXPECT_STREQ(s1.c_str(), s1_upper_.c_str());
  ToLower(s1);
  EXPECT_STREQ(s1.c_str(), s1_lower_.c_str());
  ToLower(s2);
  EXPECT_STREQ(s2.c_str(), s2_lower_.c_str());
  ToUpper(s2);
  EXPECT_STREQ(s2.c_str(), s2_upper_.c_str());
}